package com.goldplusgold.tradedelay.app.trade.dialog;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.goldplusgold.support.lib.base.fragment.FragmentBasicDialog;
import com.goldplusgold.tradedelay.app.R;
import com.goldplusgold.network.lib.http.protobuf.Market;
import com.goldplusgold.tradedelay.app.trade.activity.ProfitAndLossActivity;

/**
 * Created by admin on 2017/5/27.
 */

public class WarmTipDialog extends FragmentBasicDialog {
    Market.SltpRecord sltpRecord;
    private TextView mTextViewHandWarmTip;
    private TextView mTextViewEntrustPriceWarmTip;
    private TextView mTextViewTriggerPriceWarmTip;
    private TextView mTextViewTimeWarmTip;
    private TextView mTextViewTypeWarmTip;
    private boolean haveNoSave;
    private TextView mTextViewEditStateWarmTip;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStyle(DialogFragment.STYLE_NO_TITLE, 0);
    }


    public void setSltpRecord(Market.SltpRecord sltpRecord) {
        this.sltpRecord = sltpRecord;
    }

    public void setHaveNoSave(boolean haveNoSave) {
        this.haveNoSave = haveNoSave;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment

        View view = inflater.inflate(R.layout.fragment_warm_tip, container, false);
        mTextViewTypeWarmTip = (TextView) view.findViewById(R.id.id_text_view_type_warm_tip);
        mTextViewTimeWarmTip = (TextView) view.findViewById(R.id.id_text_view_time_warm_tip);
        mTextViewTriggerPriceWarmTip = (TextView) view.findViewById(R.id.id_text_view_trigger_price_warm_tip);
        mTextViewEntrustPriceWarmTip = (TextView) view.findViewById(R.id.id_text_view_entrust_price_warm_tip);
        mTextViewHandWarmTip = (TextView) view.findViewById(R.id.id_text_view_hand_warm_tip);
        mTextViewEditStateWarmTip = (TextView) view.findViewById(R.id.id_text_view_edit_state_warm_tip);

        view.findViewById(R.id.confim_txt).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Activity activity = getActivity();
                if (activity instanceof ProfitAndLossActivity) {
                    ((ProfitAndLossActivity) activity).loadDataAction();
                }
                getDialog().dismiss();
            }
        });
        return view;
    }


    @Override
    public void onStart() {
        super.onStart();
        if (sltpRecord == null) {
            return;
        }

        String prodCode = sltpRecord.getProdCode();
        String content = "当前";
        if (!TextUtils.isEmpty(prodCode)) {
            switch (prodCode) {
                case "Au(T+D)":
                    content = content + "【黄金延期】/";
                    break;
                case "Ag(T+D)":
                    content = content + "【白银延期】/";
                    break;
                case "mAu(T+D)":
                    content = content + "【迷你黄金延期】/";
                    break;
            }
        }
        String bearBullType = sltpRecord.getBearbullType();
        if (!TextUtils.isEmpty(bearBullType)) {
            switch (bearBullType) {
                case "BEAR":
                    content = content + "【空头】";
                    break;
                case "BULL":
                    content = content + "【多头】";
                    break;
            }
        }

        mTextViewTypeWarmTip.setText(content);
        String value = "已于" + sltpRecord.getTriggerTime() + "触发";
        String sltype = sltpRecord.getSltpType();
        if (!TextUtils.isEmpty(sltype)) {
            switch (sltype) {
                case "TP":
                    value = value + "【止盈】，";
                    break;
                case "SL":
                    value = value + "【止损】，";
                    break;
            }
        }

        mTextViewTimeWarmTip.setText(value);
        mTextViewTriggerPriceWarmTip.setText("触发价：" + sltpRecord.getSltpPrice() + "元，");
        mTextViewEntrustPriceWarmTip.setText("委托价：" + sltpRecord.getCommissionPrice() + "元，");
        mTextViewHandWarmTip.setText("手数：" + sltpRecord.getLots() + "手");

        if (haveNoSave) {
            mTextViewEditStateWarmTip.setVisibility(View.VISIBLE);
        } else {
            mTextViewEditStateWarmTip.setVisibility(View.GONE);
        }
    }
}
